package top.huhuiyu.teachproject.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import top.huhuiyu.teachproject.base.BaseDataResult;
import top.huhuiyu.teachproject.entity.TbFile;
import top.huhuiyu.teachproject.service.FileService;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/file")
@RequiredArgsConstructor
public class FileController {
  private final FileService fileService;

  @PostMapping("")
  public BaseDataResult<TbFile> upload(TbFile fileinfo, MultipartFile file) {
    return fileService.upload(fileinfo, file);
  }

  @GetMapping("/{fid}")
  public void download(@PathVariable("fid") Integer fid, HttpServletResponse response) {
    fileService.download(fid, response);
  }
}
